# 使用官方的 Python 运行时环境作为父镜像
FROM python:3.10

# 将当前目录内容复制到位于 /app 中的容器中
COPY . /app

# 设置工作目录为 /app
WORKDIR /app
# 安装 supervisor
# RUN apt-get update && apt-get install -y supervisor

# 配置supervisor
# COPY extension/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# 更新pip
RUN pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

# 设置static文件夹权限为777
RUN chmod -R 777 /app/static
RUN chmod -R 777 /app/runtime
# RUN chmod -R 777 /app/runtime/uploads
RUN chmod +x /app/start.sh

# 复制 wait-for-it.sh 脚本
COPY wait-for-it.sh /usr/local/bin/wait-for-it.sh
RUN chmod +x /usr/local/bin/wait-for-it.sh

# 安装 anyio 必须在 requirements.txt 之前 --no-cache-dir
RUN pip install  anyio==3.4.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装任何需要的包 --no-cache-dir 
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple  --no-cache-dir

# 让端口 80 可用于该容器之外的环境
EXPOSE 7000

# 定义环境变量
ENV TITLE='dockerfile_fastapi' \
    FASTAPI_VISION="0.0.1" \
    DB_BASE_TYPE='mysql' \
    DB_BASE_HOST='127.0.0.1' \
    DB_BASE_PORT=3306 \
    DB_BASE_DBNAME='sqlmodel' \
    DB_BASE_USER='root' \
    DB_BASE_PASSWORD='123456' \
    REDIS_HOST='127.0.0.1' \
    REDIS_PORT=6379 \
    REDIS_DB=0 \
    REDIS_EXPIRE=7200 \
    RABBITMQ_HOST='127.0.0.1' \
    RABBITMQ_PORT=5672 \
    RABBITMQ_DEFAULT_USER='rabbit' \
    RABBITMQ_DEFAULT_PASS='123456' 

# cmd 执行 star.sh脚本
# 启动uvicorn
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7000"]
CMD ["sh","/app/start.sh"]
